﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using myschoolDal;

namespace school
{
    public partial class addstuinformation : Form
    {
        //private static string role;
        private static long ID;
        private static string Password;
        private static string _Name;//命名重复
        private static string Major;
        private static string Grade;
        private static string Sex;

        public addstuinformation()
        {
            InitializeComponent();
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //检查输入信息是否为空
            if (name_textBox.Text == "" || ID_textBox.Text == "" || grade_comboBox.SelectedText == "" || major_comboBox.SelectedText == "" || passwd_textBox.Text == "")
            {
                if (!sex1.Checked && !sex2.Checked)
                {
                    MessageBox.Show("错误：" + bug.Class1.worng4003 + " \n错误代码：Wrong4003", "提示");
                    //return button1_Click(object sender, EventArgs e);
                }
            }
            else
            {
                //获取输入的各个信息
                ID = Convert.ToInt64(ID_textBox.Text.Trim());
                _Name = name_textBox.Text.Trim().ToString();
                Grade = grade_comboBox.SelectedItem.ToString();
                Major = major_comboBox.SelectedItem.ToString();
                Password = passwd_textBox.Text.Trim();
                if (sex1.Checked)
                {
                    Sex = "男";
                }
                else if (sex2.Checked)
                {
                    Sex = "女";
                };

                // 账号存在
                if (stuservers.CheckID(ID))
                {
                    MessageBox.Show("错误：" + bug.Class1.woring5001 + "\n错误代码：wrong5001", "提示");
                }
                else
                {
                    manserver.AddStuInformation(ID, _Name, Major, Grade, Sex, Password);
                }
            }
        }
    }
}
